import java.util.*;

public class P1047 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 读取马路长度和区域数目
        int l = scanner.nextInt();
        int m = scanner.nextInt();

        // 读取所有区域
        int[][] regions = new int[m][2];
        for (int i = 0; i < m; i++) {
            regions[i][0] = scanner.nextInt();
            regions[i][1] = scanner.nextInt();
        }

        // 按照起始坐标排序
        Arrays.sort(regions, Comparator.comparingInt(a -> a[0]));

        // 合并重叠的区域
        List<int[]> merged = new ArrayList<>();
        int start = regions[0][0];
        int end = regions[0][1];

        for (int i = 1; i < m; i++) {
            if (regions[i][0] <= end + 1) { // 区域重叠或相邻
                end = Math.max(end, regions[i][1]);
            } else {
                merged.add(new int[]{start, end});
                start = regions[i][0];
                end = regions[i][1];
            }
        }
        merged.add(new int[]{start, end});

        // 计算被移走的树总数
        int removedTrees = 0;
        for (int[] region : merged) {
            removedTrees += (region[1] - region[0] + 1);
        }

        // 计算剩余树木数量（总树数 = l + 1，因为从0到l）
        int remainingTrees = (l + 1) - removedTrees;

        System.out.println(remainingTrees);

        scanner.close();
    }
}
